package com.src.myapplication.ui.view.fragmentzhibo;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.src.myapplication.R;
import com.src.myapplication.base.BaseFragmentSwp;
import com.src.myapplication.bean.CaiYiben;
import com.src.myapplication.config.UrlConfig;
import com.src.myapplication.utils.UIManager;
import com.src.myapplication.widget.CommonAdapter;
import com.src.myapplication.widget.PlayActivity;
import com.src.myapplication.widget.base.ViewHolder;
import com.src.myapplication.widget.utils.GlideCircleTransform;

import java.util.List;

/**
 * Created by Administrator on 2016/10/21.
 */
public class CaiYi extends BaseFragmentSwp {

    private RecyclerView mRcv;
    @Override
    protected void initData(View view) {
        mRcv = (RecyclerView) view.findViewById(R.id.rcv);
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_remen;
    }

    @Override
    public int getid() {
        return R.id.sw;
    }

    @Override
    public String geturl() {
        return UrlConfig.ZhiBo.ZHIBO_FUJIN_CAIYI;
    }


    @Override
    public Class<?> getben() {
        return CaiYiben.class;
    }


    @Override
    public void addList(String list) {
        if (list != null) {

            Gson gson = new Gson();
            final CaiYiben caiYiben = gson.fromJson(list, CaiYiben.class);
            List<CaiYiben.InfoBean.LivelistBean> livelist = caiYiben.getInfo().getLivelist();
            CommonAdapter<CaiYiben.InfoBean.LivelistBean> adapter1 = new CommonAdapter<CaiYiben.InfoBean.LivelistBean>(getContext(), R.layout.fragment_remen_list, livelist) {
                @Override
                protected void convert(ViewHolder holder,CaiYiben.InfoBean.LivelistBean tuiJian, int position) {
                    ImageView view = holder.getView(R.id.sdv);//头像控件
                    ImageView rom = holder.getView(R.id.rom);//内容控件
                    TextView guankan = holder.getView(R.id.renshu);//观看人数控件
                    TextView name = holder.getView(R.id.name);//姓名控件
                    TextView dizhi = holder.getView(R.id.dizhi);//地址控件

                    double users = tuiJian.getUsers();//观看人数
                    final String string;
                    if (users > 10000) {
                        double renshu = users / 10000;
                        string = new String(renshu + "万");//观看人数
                    } else {
                        string = new String(String.valueOf(users));
                    }
                    //地址
                    final String avatar = tuiJian.getUser().getAvatar();
                    dizhi.setText(tuiJian.getUser().getCity());
                    //观看人数
                    guankan.setText(string);
                    //名字
                    String nickname = tuiJian.getUser().getNickname();
                    name.setText(nickname);
                    //内容图像
                    Glide.with(getContext()).load(avatar).into(rom);
                    //头像图片地址
                    Glide.with(getContext()).load(avatar).transform(new GlideCircleTransform(getContext())).into(view);
                     String rtmp = tuiJian.getRtmp();
                    int uid = tuiJian.getUid();
                    final String[] data=new String[]{String.valueOf(uid),nickname,avatar,rtmp};

                    rom.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            UIManager.startActivity(getContext(), PlayActivity.class,data);
                        }
                    });
                }
            };

            LinearLayoutManager manager = new LinearLayoutManager(getContext());
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            mRcv.setLayoutManager(manager);
            mRcv.setAdapter(adapter1);
        }
    }
    @Override
    public void showLoadFailMsg() {

    }



}